﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HomeStayWebCP.Models;
using DAL;

namespace HomeStayWebCP.Controllers
{
    public class LikesController : Controller
    {
        //
        // GET: /Likes/

        public ActionResult Index()
        {
            return View();
        }

        #region Hoangdx Code Like

        public ActionResult InsertLikePost()
        {
            string username = HttpContext.Session["username"].ToString();
            int postID = (int.Parse(HttpContext.Session["PostID"].ToString()));

            LikeModel model = new LikeModel();
            bool check = model.InsertLikes(postID, username);
            //Lay lai so luot like bai post
            int likeNumber = model.CountLikeOfPost(postID);
            //bool check = true;
            if (Request.IsAjaxRequest())
            {
                return Json(new { check, likeNumber }, "application/json");//gui du lieu tra ve view .bien chuyen la count
            }
            else
            {
                return PartialView("Posts/ViewPost.cshtml");//chua test
            }
        }

        #endregion

    }
}
